<?php

class GenerationPDF extends CI_Controller
{
	public function __construct()
	{
		parent::__construct();

		$this->load->model('ActionsDeCommunication/ActionDeCommunication');
		$this->load->model('ActionsDeCommunication/FicheAction');
		$this->load->model('ActionsDeCommunication/Tache');
		$this->load->model('ActionsDeCommunication/Depense');
		$this->load->model('ActionsDeCommunication/Recette');
		$this->load->model('Utilisateurs/Participe');
		$this->load->model('Utilisateurs/Etudiants');
		$this->load->model('Utilisateurs/Enseignant');
		$this->load->model('ActionsDeCommunication/Forum');
		$this->load->model('ActionsDeCommunication/Theme');
		$this->load->model('ActionsDeCommunication/Etat');
		$this->load->model('ActionsDeCommunication/FicheForum');
		$this->load->model('ActionsDeCommunication/EvaluationEleve');
		$this->load->model('Utilisateurs/AttenteForum');

		include model_chemin('putDateJJMMAAAA');
	}
	
	public function ficheAction($id)
	{
		$adc = ActionDeCommunication::findById($id);
		$etudiants = ActionDeCommunication::findEtudiants($id);
		$taches = Tache::findByIdAction($id);
		$depenses = Depense::findByIdAction($id);
		$recettes = Recette::findByIdAction($id);
		$fba = FicheAction::findByIdAction($id);

		$code_adc = $adc->getCode();

		ob_start();
		include view_chemin('FicheAction/templateFicheAction', 'php');
		$content = ob_get_clean();

		include model_chemin('html2pdf_v4.03/html2pdf.class', 'php');
		// convert in PDF
		try
		{
			$html2pdf = new HTML2PDF('P', 'A4', 'fr', true, 'UTF-8', 20);
			$html2pdf->setDefaultFont('Arial');
			$html2pdf->writeHTML($content);
			$html2pdf->Output($code_adc.'_-_'.$adc->getAnneeScolaire().'.pdf', 'D');
			
		}
		catch(HTML2PDF_exception $e)
		{
			echo $e;
			exit;
		}
		exit;
	}
	
	public function ficheForum($id)
	{
		$forum = Forum::findById($id);
		$ficheBilanForum = FicheForum::findById($id);

		if(($etu = $forum->getEtudiant1()) != null)
			$EvalEtudiants[] = EvaluationEleve::findById($id, $etu->getId());
		
		if(($etu = $forum->getEtudiant2()) != null)
			$EvalEtudiants[] = EvaluationEleve::findById($id, $etu->getId());
		
		$code_forum = $forum->getCode();
		
		ob_start();

		include view_chemin('FicheForum/templateFicheBilanForum', 'php');
		$content = ob_get_clean();
		
		include model_chemin('html2pdf_v4.03/html2pdf.class', 'php');
		// convert in PDF
		try
		{
			$html2pdf = new HTML2PDF('P', 'A4', 'fr', true, 'UTF-8', 20);
			$html2pdf->writeHTML($content);
			$html2pdf->Output($code_forum.'_-_'.$forum->getAction()->getAnneeScolaire().'.pdf', 'D');
		}
		catch(HTML2PDF_exception $e)
		{
			echo $e;
			exit;
		}
		exit;
	}
}
?>